Skip to main content

Input to Main Model

A CSDL model is composed hierarchically, with the main model at the top of the hierarchy and the models representing the various subsystems below it. A CSDL model takes input values from outside the model and computes outputs given those inputs. Inputs from outside the model can be created at any level in the model hierarchy.

In this example, a single input to the main model is created within the model. There is only one model in the hierarchy in this example, which makes this model the main model. To create an input to the main model, use the Model.create_input method from within any model in the hierarchy. The model in this example has a single input, no outputs, and no other models in the hierarchy. Once the computational model is built using the CSDL compiler back end, the variable value may be accessed using the name given in the call to Model.create_input.

from csdl_om import Simulatorfrom csdl import Modelimport numpy as np

class ExampleSimple(Model):
    def define(self):        z = self.create_input('z', val=10)

sim = Simulator(ExampleSimple())sim.run()
print('z', sim['z'].shape)print(sim['z'])
[10.]